"""
@author: yqx
@file: text.py
@time: 2024/8/12 21:22
"""
import csv
import json
import data_get_url
import pandas as pd
pd.read_csv("end_pois_code.csv")
pois_code=pd.read_csv("end_pois_code.csv")
df2=pois_code[16:20]
poisname=df2.iterrows()
# print(poisname)
def dict_to_string(row):
    return ', '.join(row)

for index,row in poisname:
    csvname=row['职位']
    poiscode=row['编号']
    # print(csvname)
    # print(poiscode)
    url=f"https://www.zhipin.com/wapi/zpgeek/search/joblist.json?scene=1&query=&city=100010000&experience=&payType=&partTime=&degree=&industry=&scale=&stage=&position={poiscode}&jobType=&salary=&multiBusinessDistrict=&multiSubway=&page=1&pageSize=30"
    cookie={
    "lastCity": "100010000",
    "gdxidpyhxdE": "2RCycwO44j4qmig9HU2qn95JtowXCx46IApT%2Ff9u%2FsaopsIceg79UUNkZZlTWz%5CZnNizUpszUd9U2dC19%5Ca%2By61tUa0q19VmmNLmGHg036Pc%5CZ2fUKedl2UDn%5CSwkrIKcHC6z1JtETGU8Rbg2l%2BmUWZ7vSVC%2BcbsX8SksJToucjWBoDH%3A1723472725873",
    "wt2": "Dx9UevSKKWnEQY8nQNZR1gkfwIV4XaFeQmFlTe7LxiygJpzxQsK7mcXqD47YmxBy1prN7FqEM1baHv2CyZUFzgg~~",
    "wbg": "0",
    "zp_at": "-G82kzDvKOvCyh7cjrli3ivNXuLwoSjkbWJfp6YSHOk~",
    "__g": "-",
    "__zp_stoken__": "de00fw4vDjcK9GDtpZRgUGV5%2BUcK6ZsOBXHR7w43Cu3R%2FwqZ5cl3CvWXDjFHDiGnCm8K0wrfDhcK%2BY8KqUMK0X8KpU8KhWcOPwqrCo8K5w71awqHEpcSDw5DFhcSOwrjDh8KoRTMXFxwWEBcXHBYQFBQKGB4SEhETHRkZChgeOjLCt8KjO0VITDBZXl4SXGhsV2dQFlpWU0ZECxxuaEQ5R0xGQMOJR8OJHsOOR8K6FMOIQMK6Z0xOQEfDhRcrTFkLw4%2FDgjbDhG4YbRRJC8OcaMSIwr7CtsOJxI88RUXDjMWHT0QhOkU7TkRPTjtEMU8xw5BpxI%2FCtcK3w4XDoDRMJUNEREY7O0REQEVJMERHwoIxREc8SRQYHwsKKknCu8ONw4bDrkRE",
    "__c": "1724421480",
    "__a": "37782403.1718675716.1724389278.1724421480.290.22.9.15",
    "bst": "V2RN4nE-f0219oVtRuzRgZKiu47DrWxCk~|RN4nE-f0219oVtRuzRgZKiu47DrRwio~"
}
    result = data_get_url.download_cookie(url, cookies=cookie)
    # # print(result)
    data=json.loads(result)
    joblist=data["zpData"]["jobList"]
    # print(joblist)

    end_csvname=csvname.replace("/","_")
    filepath=f"./具体数据/{end_csvname}.csv"
    with open(filepath,"w",encoding='utf-8')as f:
        csvwriter=csv.writer(f)
        head_data=["jobname","salaryDesc","jobLabels","skills","jobExperience","jobDegree","cityName","areaDistrict","businessDistrict","brandName","brandStageName","brandIndustry","brandScaleName","welfareList"]
        csvwriter.writerow(head_data)
        for job in joblist:
            jobname=job["jobName"]
            # print(jobname)
            salaryDesc=job["salaryDesc"]
            jobLabels=dict_to_string(job["jobLabels"])
            # jobLabels=job["jobLabels"]
            skills=dict_to_string(job["skills"])
            # skills=job["skills"]
            jobExperience=job["jobExperience"]
            jobDegree=job["jobDegree"]
            cityName=job["cityName"]
            areaDistrict=job["areaDistrict"]
            businessDistrict=job["businessDistrict"]
            brandName=job["brandName"]
            brandStageName=job["brandStageName"]
            brandIndustry=job["brandIndustry"]
            brandScaleName=job["brandScaleName"]
            # print(brandScaleName)
            # welfareList=job["welfareList"]
            welfareList=dict_to_string(job["welfareList"])
            # print(welfareList)
            end_data=[jobname,salaryDesc,jobLabels,skills,jobExperience,jobDegree,cityName,areaDistrict,businessDistrict,brandName,brandStageName,brandIndustry,brandScaleName,welfareList]
            # csvwriter.writerow(jobname,salaryDesc,jobLabels,skills,jobExperience,jobDegree,cityName,areaDistrict,businessDistrict,brandName,brandStageName,brandIndustry,brandScaleName,welfareList)
            csvwriter.writerow(end_data)
            # print("-------------完成----------------")

